package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.InquirylineApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.DataResponseListInquiryLineDTO;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.InquiryLineDTO;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.InquiryLineDTOResponse;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.dao.InquiryOrderLineDao;
import com.clickpaas.materialsprocurement.entity.InquiryOrderLineEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Repository
public class InquiryOrderLineDaoImpl implements InquiryOrderLineDao {
    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private InquirylineApi inquirylineApi;
    /**
     * 根据条件查询询价单行对象数据
     *
     * @param inquiryOrderLineEntity
     */
    @Override
    public List<InquiryLineDTOResponse> getInquiryOrderByCondtion(InquiryOrderLineEntity inquiryOrderLineEntity) {
        InquiryLineDTO inquiryLineDTO = materalsDtoBean.inquiryLineDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(inquiryOrderLineEntity,inquiryLineDTO);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】", inquiryOrderLineEntity);
        }
        return queryInquiryOrderLine(inquiryLineDTO);
    }

    private List<InquiryLineDTOResponse> queryInquiryOrderLine(InquiryLineDTO inquiryLineDTO){
        DataResponseListInquiryLineDTO inquiryLineUsingPOST = inquirylineApi.findInquiryLineUsingPOST(inquiryLineDTO);
        if(null == inquiryLineUsingPOST
                || null == inquiryLineUsingPOST.getData()
                || inquiryLineUsingPOST.getData().size()<=0
                || !"SUCCESS".equals(inquiryLineUsingPOST.getMessage())){
            log.info("当前查询的数据：【{}】",inquiryLineUsingPOST);
            return null;
        }
        return inquiryLineUsingPOST.getData();
    }
}
